﻿using System;

namespace UniRx.Operators
{
	// Token: 0x020002CF RID: 719
	internal class PairwiseObservable<T> : OperatorObservableBase<Pair<T>>
	{
		// Token: 0x06000F76 RID: 3958 RVA: 0x00047BFC File Offset: 0x00045FFC
		public PairwiseObservable(IObservable<T> source) : base(source.IsRequiredSubscribeOnCurrentThread<T>())
		{
			this.source = source;
		}

		// Token: 0x06000F77 RID: 3959 RVA: 0x00047C11 File Offset: 0x00046011
		protected override IDisposable SubscribeCore(IObserver<Pair<T>> observer, IDisposable cancel)
		{
			return this.source.Subscribe(new PairwiseObservable<T>.Pairwise(observer, cancel));
		}

		// Token: 0x040008FF RID: 2303
		private readonly IObservable<T> source;

		// Token: 0x020002D0 RID: 720
		private class Pairwise : OperatorObserverBase<T, Pair<T>>
		{
			// Token: 0x06000F78 RID: 3960 RVA: 0x00047C28 File Offset: 0x00046028
			public Pairwise(IObserver<Pair<T>> observer, IDisposable cancel) : base(observer, cancel)
			{
			}

			// Token: 0x06000F79 RID: 3961 RVA: 0x00047C54 File Offset: 0x00046054
			public override void OnNext(T value)
			{
				if (this.isFirst)
				{
					this.isFirst = false;
					this.prev = value;
					return;
				}
				Pair<T> value2 = new Pair<T>(this.prev, value);
				this.prev = value;
				this.observer.OnNext(value2);
			}

			// Token: 0x06000F7A RID: 3962 RVA: 0x00047CA0 File Offset: 0x000460A0
			public override void OnError(Exception error)
			{
				try
				{
					this.observer.OnError(error);
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x06000F7B RID: 3963 RVA: 0x00047CD8 File Offset: 0x000460D8
			public override void OnCompleted()
			{
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x04000900 RID: 2304
			private T prev = default(T);

			// Token: 0x04000901 RID: 2305
			private bool isFirst = true;
		}
	}
}
